// JavaScript Document
var ISPRESSED=0;
var INNER=0;
var TEMPADD=0;
var indexx=0;
var indexy=0;
var nowid =0;
var noteid = 0;
$().ready(function(){
	$('#he').css('left',$('#main').position().left);
	$('#he').css('top',$('#main').position().top);	
	$('#main').mousedown(function(){ISPRESSED=1;TEMPADD=mousePos(null).x;});//当鼠标在看板中按下时
	$('#main').mouseup(function(){ISPRESSED=0;});//当鼠标松开时
	$('#main').mouseover(function(){INNER=1;});//当鼠标进入时
	$('#main').mouseout(function(){INNER=0;ISPRESSED=0;});//当鼠标进入时
	$('#next0,#pre0,#next1,#pre1').click(function(){ 
		var tempobj=$(this);
        var index=0;
		var index_y;
		if(tempobj.attr('id').match(/0$/)){
			index_y=indexx;
		}else {
			index_y=indexy;
			index=1;
		}    
	var h=0;
        var tst='div';
        if(index==0){tst='img';}
     		$("#photoc"+index+index_y).children(tst).fadeOut(300,function(){
			if(tempobj.attr('id').match(/^n/)){//后一组数据加载
            
/*=============>加载前面的数据*/getleftdata($("#photoc"+index+index_y),index);	 
            }else if(tempobj.attr('id').match(/^p/)){//前一组数据加载
				h=1;
/*=============>加载后面的数据*/getleftdata($("#photoc"+index+index_y),index);  /*这里如果要区分到底是日志还是图片的话就给函数多传个参数index,index==0的时候是上面3个==1的时候是下面3个*/
            } 
			$("#photoc"+index+index_y).children().fadeIn(300);
			if(h==0){
					 index_y++;
			     	 if(index_y>2){index_y=0;}
				}else{
					 index_y--;
					 if(index_y<0){index_y=2;}
					}
			if(index==0){indexx=index_y;}else{indexy=index_y;}				
				}); 
			
		});//当鼠标移动时

});
function mousePos(e){ 
var x,y; 
var e = e||window.event; 
return { 
x:e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft, 
y:e.clientY+document.body.scrollTop+document.documentElement.scrollTop 
}; 
}
function getleftdata(obj,index){
  var uid = $('#uid').val();
  if(index == 0)
  {
  $.post('photoMove',{uid:uid},function(data){
    var josnObj = $.parseJSON(data);

    if(josnObj.status == 1)
     {
       // if(josnObj.data[3+nowid]['ph_name']!='')
       var touch = 3+ nowid;
       if(touch<josnObj.data.length)
        {
        var path = "../../Tpl/default/Public/upload/"+josnObj.data[3+nowid]['ph_name'];
        $(obj).children('img').attr("src",path); 
        nowid++;
        }
        else
        {
        alert('已经到达最后一张！');
        }
    }
    else
    {
        alert(jsonObj.info);
    }
   });
  }
  if(index == 1){
 $.post('NoteMove',{uid:uid},function(data){
    var jsonObj = $.parseJSON(data);  
    if(jsonObj.status == 1)
     {
        var touchnote = 3+noteid;
        if(touchnote<jsonObj.data.length)
        {
        var content = jsonObj.data[3+noteid]['title'];
       // var content = "<a href='toNote/nid/'"+josnObj.data[3+noteid]['n_id']+">"+title+"</a>"
        $(obj).children().html(content); 
        noteid++;
        }
        else
        {
        alert('已经到达最后一张！');
        }
    }
    else
    {
        alert(jsonObj.info);
    }
  
  });
 }
}

//非数字过滤器
function filter(str) {
    return Number(str.replace(/[a-z]/gi, ""));
}	


